package net.hn.hnms.biz.safety.fire.group.service.impl;

import net.hn.hnms.biz.safety.fire.company.domain.vo.SGJCAlarmVo;
import net.hn.hnms.biz.safety.fire.company.service.CompanyFireService;
import net.hn.hnms.biz.safety.fire.group.service.GroupFireService;
import net.hn.hnms.sys.common.core.constant.Constants;
import net.hn.hnms.sys.common.core.exception.HuaNengException;
import net.hn.hnms.sys.common.redis.domain.SysOrganizationVo;
import net.hn.hnms.sys.common.redis.utils.RedisUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 公司端火灾接口实现类
 */
@Service
public class GroupFireServiceImpl implements GroupFireService {
    /**
     * 火灾公司端接口
     */
    @Resource
    private CompanyFireService companyFireService;

    /**
     * 获取今日束管监测报警列表(内因火灾)
     * @return
     */
    @Override
    public List<SGJCAlarmVo> getTodaySGJCAlarmList() {
        //获取当前公司的所有煤矿
        SysOrganizationVo sysOrganizationVo = RedisUtils.getCacheObject(Constants.SYS_CODESUB_KEY + 0);
        if (sysOrganizationVo == null) {
            throw new HuaNengException(Constants.FAIL, "无法获集团的子煤矿信息，请检查词典");
        }
        List<SGJCAlarmVo> voList = new ArrayList<>();
        for (SysOrganizationVo organizationVo : sysOrganizationVo.getSubCodeList()) {
            //遍历集团所有公司
            List<SGJCAlarmVo> list = companyFireService.getTodaySGJCAlarmList(organizationVo.getOrgCode());
            for (SGJCAlarmVo nowSensorAlarmVo : list) {
                voList.add(nowSensorAlarmVo);
            }
        }
        return voList;
    }
}
